home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / DebugWindow1.4.sit / DebugWindow 1.4 ƒ / Debug.c next >
Text File  |  1993-09-08  |  2KB  |  107 lines

  1. //============================================================================
  2. //
  3. //    This is the Think C 6.0 code to send a message to the DebugWindow server
  4. //    (in other words, this is the code to DebugWindow.Lib that came with your
  5. //    DebugWindow package).  I'm providing this code to document the AppleEvent
  6. //    procedures necessary to communicate with DebugWindow; those of you who
  7. //    need a specialized version, or need to port it to another environment
  8. //    (such as Pascal or MacApp) should find everything that you need to know
  9. //    right here.
  10. //
  11. //    If you implement this into a new environment, I'd appreciate it if you
  12. //    could send me the new modules so that I can include them with the next
  13. //    release of DebugWindow (with the proper credits going to you, of course!).
  14. //
  15. //
  16. //    Here are the necessary steps to send a string to DebugWindow:
  17. //
  18. //        ・ create an AppleEvent for signature 'LdbW' with a type of 'misc/dmsg'
  19. //
  20. //        ・ add a parameter of type 'keyDirectObject/typeChar' passing a pointer
  21. //          to the string to display and its length
  22. //
  23. //        ・ send it on its way
  24. //
  25. //============================================================================
  26.  
  27.  
  28. #include    <stdio.h>
  29. #include    <stdarg.h>
  30. #include    <AppleEvents.h>
  31.  
  32.  
  33.  
  34. void __SendToDebugWindow ( char *stringToSend );
  35.  
  36.  
  37.  
  38.  
  39. void Debug ( char *format, ... )
  40. {
  41.     va_list        argptr;
  42.     long        len;
  43.     OSErr        err;
  44.     char        tDebugString [512];
  45.  
  46.     va_start ( argptr, format );
  47.     len = (long)vsprintf ( tDebugString, format, argptr );
  48.     va_end ( argptr );
  49.     if ( len > 0 )
  50.         __SendToDebugWindow ( tDebugString );
  51. }
  52.  
  53.  
  54.  
  55.  
  56. void ClearDebugWindow ()
  57. {
  58.     __SendToDebugWindow ( "~c" );
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65. void DebugTimestamp ()
  66. {
  67.     __SendToDebugWindow ( "~t" );
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. void __SendToDebugWindow ( char *stringToSend )
  76. {
  77.     AEAddressDesc    address;
  78.     AppleEvent        appleEvent, reply;
  79.     OSType            targetSig;
  80.     
  81.     targetSig = 'LdbW';
  82.  
  83.     if ( AECreateDesc ( typeApplSignature, (Ptr)&targetSig, 
  84.                         sizeof targetSig, &address ) == 0 ) {
  85.  
  86.         if ( AECreateAppleEvent ( 'misc', 'dmsg', &address, kAutoGenerateReturnID,
  87.                                    kAnyTransactionID, &appleEvent ) == 0 ) {
  88.  
  89.             if ( AEPutParamPtr ( &appleEvent, keyDirectObject, typeChar,
  90.                                  stringToSend, strlen (stringToSend) ) == 0 ) {
  91.  
  92.                 AESend ( &appleEvent, &reply, 
  93.                          kAEWaitReply + kAENeverInteract,
  94.                          kAENormalPriority, 
  95.                          300,                                 // up to 5 second wait..
  96.                          nil, nil );
  97.                 
  98.                 AEDisposeDesc ( &reply );
  99.             }
  100.             AEDisposeDesc ( &appleEvent );
  101.         }
  102.         AEDisposeDesc ( &address );
  103.     }
  104. }
  105.  
  106.  
  107.